# Copyright 2018- The Pixie Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

load("@io_bazel_rules_docker//container:container.bzl", "container_bundle")
load("@io_bazel_rules_docker//contrib:push-all.bzl", "container_push")
load("//bazel:images.bzl", "image_replacements", "list_image_bundle")
load("//bazel:kustomize.bzl", "kustomize_build")

package(default_visibility = ["//visibility:public"])

CLOUD_IMAGE_TO_LABEL = {
    "$(IMAGE_PREFIX)/cloud-api_server_image:$(BUNDLE_VERSION)": "//src/cloud/api:api_server_image",
    "$(IMAGE_PREFIX)/cloud-artifact_tracker_server_image:$(BUNDLE_VERSION)": "//src/cloud/artifact_tracker:artifact_tracker_server_image",
    "$(IMAGE_PREFIX)/cloud-auth_server_image:$(BUNDLE_VERSION)": "//src/cloud/auth:auth_server_image",
    "$(IMAGE_PREFIX)/cloud-config_manager_server_image:$(BUNDLE_VERSION)": "//src/cloud/config_manager:config_manager_server_image",
    "$(IMAGE_PREFIX)/cloud-cron_script_server_image:$(BUNDLE_VERSION)": "//src/cloud/cron_script:cron_script_server_image",
    "$(IMAGE_PREFIX)/cloud-indexer_server_image:$(BUNDLE_VERSION)": "//src/cloud/indexer:indexer_server_image",
    "$(IMAGE_PREFIX)/cloud-metrics_server_image:$(BUNDLE_VERSION)": "//src/cloud/metrics:metrics_server_image",
    "$(IMAGE_PREFIX)/cloud-plugin-load_db:$(BUNDLE_VERSION)": "//src/cloud/plugin/load_db:plugin_db_updater_image",
    "$(IMAGE_PREFIX)/cloud-plugin_server_image:$(BUNDLE_VERSION)": "//src/cloud/plugin:plugin_server_image",
    "$(IMAGE_PREFIX)/cloud-profile_server_image:$(BUNDLE_VERSION)": "//src/cloud/profile:profile_server_image",
    "$(IMAGE_PREFIX)/cloud-project_manager_server_image:$(BUNDLE_VERSION)": "//src/cloud/project_manager:project_manager_server_image",
    "$(IMAGE_PREFIX)/cloud-proxy_server_image:$(BUNDLE_VERSION)": "//src/cloud/proxy:proxy_server_image",
    "$(IMAGE_PREFIX)/cloud-scriptmgr_server_image:$(BUNDLE_VERSION)": "//src/cloud/scriptmgr:scriptmgr_server_image",
    "$(IMAGE_PREFIX)/cloud-vzconn_server_image:$(BUNDLE_VERSION)": "//src/cloud/vzconn:vzconn_server_image",
    "$(IMAGE_PREFIX)/cloud-vzmgr_server_image:$(BUNDLE_VERSION)": "//src/cloud/vzmgr:vzmgr_server_image",
}

kustomize_build(
    name = "pixie_staging_cloud",
    srcs = glob(
        [
            "base/**/*.yaml",
            "overlays/**/*.yaml",
            "staging/**/*.yaml",
        ],
        exclude = ["staging/kustomization.yaml"],
    ),
    kustomization = "staging/kustomization.yaml",
    replacements = image_replacements(
        image_map = CLOUD_IMAGE_TO_LABEL,
    ),
    toolchains = [
        "//k8s:image_prefix",
        "//k8s:bundle_version",
    ],
)

kustomize_build(
    name = "pixie_prod_cloud",
    srcs = glob(
        [
            "base/**/*.yaml",
            "overlays/**/*.yaml",
            "prod/**/*.yaml",
        ],
        exclude = ["prod/kustomization.yaml"],
    ),
    kustomization = "prod/kustomization.yaml",
    replacements = image_replacements(
        image_map = CLOUD_IMAGE_TO_LABEL,
    ),
    toolchains = [
        "//k8s:image_prefix",
        "//k8s:bundle_version",
    ],
)

container_bundle(
    name = "image_bundle",
    images = CLOUD_IMAGE_TO_LABEL,
    toolchains = [
        "//k8s:image_prefix",
        "//k8s:bundle_version",
    ],
)

list_image_bundle(
    name = "list_image_bundle",
    images = CLOUD_IMAGE_TO_LABEL,
    toolchains = [
        "//k8s:image_prefix",
        "//k8s:bundle_version",
    ],
)

container_push(
    name = "cloud_images_push",
    bundle = ":image_bundle",
    format = "Docker",
)
